package com.haoxi.gateway.cmpp30msg;

/**
 * Title:CMPP3.0,200409
 */

import java.io.IOException;
import java.io.InputStream;


/**
 * ʵ��CMPP3.0 CMPP_Connect_Rep
 */
public class CMPPConnectRep {
    private byte[] bodybytes;
    private int Status = -1;
    private String AuthISMG;
    private int version;

    /**
     * ����һ��CMPPConnectRep
     */
    public CMPPConnectRep () {
        bodybytes = new byte[CMPPCommon.MSG_CONNECT_REP_BODY_LENGTH];
    }

    public CMPPConnectRep ( byte[] body ) throws CMPP30Exception {
        if ( body.length != CMPPCommon.MSG_CONNECT_REP_BODY_LENGTH ) {
            throw new CMPP30Exception ( "invalid CMPPConnectRep body package!" );
        }
        bodybytes = body;
        parseBody ();
    }

    /**
     * ��ȡCMPP_Connect_Rep��Ϣ
     *
     * @param in ������
     * @throws IOException ������IOΥ��ʱ
     */
    public void read ( InputStream in ) throws IOException {    // modified by star 2006-6-3 DataInputStream 改为InputStream
        CMPPMsgHead head = new CMPPMsgHead ();
        head.read ( in );
        if ( head.getCommandID () == CMPPCommon.CMPP_CONNECT_REP ) {
            in.read ( bodybytes );
        }
        else {
            throw new IOException ( "CMPPConnectRep read error package!" );
        }
        parseBody ();
    }

    /**
     * ���ֽ������CMPPConnectRep��ֽ�
     */
    private void parseBody () {
        byte[] aresult = new byte[4];
        CMPPCommon.BytesCopy ( bodybytes, aresult, 0, 3, 0 );

        try {
            Status = CMPPCommon.Bytes4ToInt ( aresult );
        }
        catch ( Exception e ) {
            Status = -2;
        }
        //Status = bodybytes[0];
        //AuthISMG = new String(bodybytes,4,19);
        ///AuthISMG = new String(bodybytes, 1, 16);
        version = bodybytes[ 20 ];
    }

    /**
     * ȡ�÷��ص�Status
     *
     * @return Status
     */
    public int getStatus () {
        return Status;
    }

    /**
     * ȡ�÷��ص�AuthenticatorISMG
     *
     * @return AuthenticatorISMG
     */
    public String getAuthISMG () {
        return AuthISMG;
    }

    /**
     * ȡ�÷��ص�Version
     *
     * @return Version
     */
    public int getVersion () {
        return version;
    }
}